home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / Four_Array2096921102008.psc / Array Sorting Functions / frmMain.frm next >
Text File  |  2008-01-10  |  8KB  |  245 lines

  1. VERSION 5.00
  2. Begin VB.Form frmMain 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Array Sorting Functions"
  5.    ClientHeight    =   5175
  6.    ClientLeft      =   45
  7.    ClientTop       =   345
  8.    ClientWidth     =   8895
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   5175
  13.    ScaleWidth      =   8895
  14.    StartUpPosition =   2  'CenterScreen
  15.    Begin VB.Frame fraLog 
  16.       Caption         =   "Log"
  17.       Height          =   2415
  18.       Left            =   120
  19.       TabIndex        =   13
  20.       Top             =   2640
  21.       Width           =   8655
  22.       Begin VB.ListBox lstLog 
  23.          Height          =   2010
  24.          ItemData        =   "frmMain.frx":0000
  25.          Left            =   120
  26.          List            =   "frmMain.frx":0002
  27.          TabIndex        =   14
  28.          Top             =   240
  29.          Width           =   8415
  30.       End
  31.    End
  32.    Begin VB.Frame fraOutput 
  33.       Caption         =   "Output"
  34.       Height          =   2415
  35.       Left            =   5520
  36.       TabIndex        =   10
  37.       Top             =   120
  38.       Width           =   3255
  39.       Begin VB.ListBox lstOutput 
  40.          Height          =   2010
  41.          ItemData        =   "frmMain.frx":0004
  42.          Left            =   120
  43.          List            =   "frmMain.frx":0006
  44.          TabIndex        =   11
  45.          Top             =   240
  46.          Width           =   3015
  47.       End
  48.    End
  49.    Begin VB.Frame fraInput 
  50.       Caption         =   "Input"
  51.       Height          =   2415
  52.       Left            =   120
  53.       TabIndex        =   0
  54.       Top             =   120
  55.       Width           =   3255
  56.       Begin VB.CommandButton cmdLoadItems 
  57.          Caption         =   "L"
  58.          Height          =   255
  59.          Left            =   2880
  60.          TabIndex        =   15
  61.          Top             =   1920
  62.          Width           =   255
  63.       End
  64.       Begin VB.CommandButton cmdAddItem 
  65.          Caption         =   "+"
  66.          Height          =   255
  67.          Left            =   2880
  68.          TabIndex        =   2
  69.          Top             =   240
  70.          Width           =   255
  71.       End
  72.       Begin VB.CommandButton cmdRemoveItem 
  73.          Caption         =   "-"
  74.          Height          =   255
  75.          Left            =   2880
  76.          TabIndex        =   3
  77.          Top             =   600
  78.          Width           =   255
  79.       End
  80.       Begin VB.ListBox lstInput 
  81.          Height          =   2010
  82.          ItemData        =   "frmMain.frx":0008
  83.          Left            =   120
  84.          List            =   "frmMain.frx":000A
  85.          TabIndex        =   1
  86.          Top             =   240
  87.          Width           =   2655
  88.       End
  89.    End
  90.    Begin VB.Frame fraSortArray 
  91.       Caption         =   "Sort Array"
  92.       Height          =   2415
  93.       Left            =   3480
  94.       TabIndex        =   4
  95.       Top             =   120
  96.       Width           =   1935
  97.       Begin VB.CommandButton cmdSort 
  98.          Caption         =   "Sort"
  99.          Height          =   375
  100.          Left            =   480
  101.          TabIndex        =   9
  102.          Top             =   1920
  103.          Width           =   975
  104.       End
  105.       Begin VB.OptionButton optSortMethod 
  106.          Caption         =   "Shell Sort"
  107.          Height          =   255
  108.          Index           =   3
  109.          Left            =   600
  110.          TabIndex        =   8
  111.          Top             =   1560
  112.          Width           =   1215
  113.       End
  114.       Begin VB.OptionButton optSortMethod 
  115.          Caption         =   "Shaker Sort"
  116.          Height          =   255
  117.          Index           =   2
  118.          Left            =   600
  119.          TabIndex        =   7
  120.          Top             =   1200
  121.          Width           =   1215
  122.       End
  123.       Begin VB.OptionButton optSortMethod 
  124.          Caption         =   "Quick Sort"
  125.          Height          =   255
  126.          Index           =   1
  127.          Left            =   600
  128.          TabIndex        =   6
  129.          Top             =   840
  130.          Width           =   1215
  131.       End
  132.       Begin VB.OptionButton optSortMethod 
  133.          Caption         =   "Bubble Sort"
  134.          Height          =   255
  135.          Index           =   0
  136.          Left            =   600
  137.          TabIndex        =   5
  138.          Top             =   480
  139.          Width           =   1215
  140.       End
  141.       Begin VB.Label lblUsingMethod 
  142.          Caption         =   "Using;"
  143.          Height          =   255
  144.          Left            =   120
  145.          TabIndex        =   12
  146.          Top             =   240
  147.          Width           =   615
  148.       End
  149.    End
  150. End
  151. Attribute VB_Name = "frmMain"
  152. Attribute VB_GlobalNameSpace = False
  153. Attribute VB_Creatable = False
  154. Attribute VB_PredeclaredId = True
  155. Attribute VB_Exposed = False
  156. Option Explicit
  157.  
  158. Private Declare Function GetTickCount Lib "kernel32" () As Long
  159.  
  160. Private Sub cmdAddItem_Click()
  161.     Dim strTempString As String
  162.     
  163.     strTempString = InputBox("Please enter a string.", "Enter String.")
  164.     
  165.     If LenB(strTempString) > 0 Then _
  166.         lstInput.AddItem strTempString
  167.     
  168. End Sub
  169.  
  170. Private Sub cmdLoadItems_Click()
  171.     Dim strTempString As String
  172.     Dim strTempPath As String
  173.     
  174.     strTempPath = InputBox("Please enter a file path.", "Enter Path.")
  175.     
  176.     If LenB(strTempPath) = 0 Or LenB(Dir(strTempPath)) = 0 Then Exit Sub
  177.     
  178.     lstInput.Clear
  179.     Open strTempPath For Input As #1
  180.         Do Until EOF(1)
  181.             Line Input #1, strTempString
  182.             lstInput.AddItem strTempString
  183.         Loop
  184.     Close #1
  185.     
  186. End Sub
  187.  
  188. Private Sub cmdRemoveItem_Click()
  189.     
  190.     If lstInput.SelCount > 0 Then _
  191.         lstInput.RemoveItem lstInput.ListIndex
  192.     
  193. End Sub
  194.  
  195. Private Sub cmdSort_Click()
  196.     Dim i As Integer, intUpperBound As Integer
  197.     Dim strTempArray() As String
  198.     
  199.     Dim strMethodUsed As String
  200.     Dim lngStartTime As Long
  201.     Dim lngEndTime As Long
  202.     Dim dblTotalTime As Double
  203.     
  204.     If lstInput.ListCount = 0 Then Exit Sub
  205.     
  206.     intUpperBound = lstInput.ListCount - 1
  207.     ReDim strTempArray(intUpperBound) As String
  208.     
  209.     For i = 0 To intUpperBound
  210.         strTempArray(i) = lstInput.List(i)
  211.     Next i
  212.     
  213.     If optSortMethod(0).Value = True Then
  214.         strMethodUsed = "Bubble Sort"
  215.         lngStartTime = GetTickCount()
  216.         Call BubbleSort(strTempArray(), intUpperBound)
  217.         lngEndTime = GetTickCount()
  218.     ElseIf optSortMethod(1).Value = True Then
  219.         strMethodUsed = "Quick Sort"
  220.         lngStartTime = GetTickCount()
  221.         Call QuickSort(strTempArray, 0, intUpperBound)
  222.         lngEndTime = GetTickCount()
  223.     ElseIf optSortMethod(2).Value = True Then
  224.         strMethodUsed = "Shaker Sort"
  225.         lngStartTime = GetTickCount()
  226.         Call ShakerSort(strTempArray(), intUpperBound)
  227.         lngEndTime = GetTickCount()
  228.     ElseIf optSortMethod(3).Value = True Then
  229.         strMethodUsed = "Shell Sort"
  230.         lngStartTime = GetTickCount()
  231.         Call ShellSort(strTempArray(), intUpperBound)
  232.         lngEndTime = GetTickCount()
  233.     End If
  234.     dblTotalTime = (lngEndTime - lngStartTime) / 1000
  235.     
  236.     lstOutput.Clear
  237.     For i = 0 To intUpperBound
  238.          lstOutput.AddItem strTempArray(i)
  239.     Next i
  240.     
  241.     lstLog.AddItem CStr(lstInput.ListCount) + " items sorted in " + CStr(dblTotalTime) + " seconds, using the " + strMethodUsed + " method."
  242.     lstLog.ListIndex = lstLog.NewIndex
  243.     
  244. End Sub
  245.